package com.dev.dream.exochatlockscreen.receive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.dev.dream.exochatlockscreen.LockScreenAppActivity;
import com.dev.dream.exochatlockscreen.EXOChatKeypadPreferences;
import com.dev.dream.exochatlockscreen.service.SLockscreen;

public class LockScreenReeiver extends BroadcastReceiver {
	public static boolean wasScreenOn = true;

	@Override
	public void onReceive(Context context, Intent intent) {
		try {
			// Toast.makeText(context, "" + "enterrrrrr",
			// Toast.LENGTH_SHORT).show();
			if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
				// Toast.makeText(context, "" + "screeen off",
				// Toast.LENGTH_SHORT).show();
				// Log.d("Kai", "ACTION_SCREEN_OFF");
				wasScreenOn = false;

				if (EXOChatKeypadPreferences.getInstance().isEnableLockscreen()) {
					if (!SLockscreen.IS_RUN) {
						SLockscreen.IS_RUN = true;
						Intent intent11 = new Intent(context,
								LockScreenAppActivity.class);
						intent11.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

						context.startActivity(intent11);
					}
				}

				// do whatever you need to do here
				// wasScreenOn = false;
			} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {

				// Log.d("Kai", "SCREEN ON");
				wasScreenOn = true;

				// Intent intent11 = new Intent(context,
				// LockScreenAppActivity.class);
				// intent11.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

				// context.startActivity(intent11);
				// Toast.makeText(context, "" + "start activity",
				// Toast.LENGTH_SHORT).show();
				// and do whatever you need to do here
				// wasScreenOn = true;
			} else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
				/*
				 * KeyguardManager.KeyguardLock k1; KeyguardManager km
				 * =(KeyguardManager
				 * )context.getSystemService(context.KEYGUARD_SERVICE); k1 =
				 * km.newKeyguardLock("IN"); k1.disableKeyguard();
				 */
				// Log.d("Kai", "FLAG_ACTIVITY_NEW_TASK");

				if (EXOChatKeypadPreferences.getInstance().isEnableLockscreen()) {
					if (SLockscreen.instance == null) {
						context.startService(new Intent(context,
								SLockscreen.class));

					}

					if (!SLockscreen.IS_RUN) {
						SLockscreen.IS_RUN = true;
						Intent intent11 = new Intent(context,
								LockScreenAppActivity.class);
						intent11.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

						context.startActivity(intent11);
					}
				}
				// Intent intent11 = new Intent(context,
				// LockScreenAppActivity.class);
				//
				// intent11.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				// context.startActivity(intent11);

				// Intent intent = new Intent(context, LockPage.class);
				// context.startActivity(intent);
				// Intent serviceLauncher = new Intent(context,
				// UpdateService.class);
				// context.startService(serviceLauncher);
				// Log.v("TEST", "Service loaded at start");
			}

		} catch (Exception ex) {
		}

	}

}
